package com.stone.boot.file.api.controller.v1;

import com.stone.boot.file.app.service.OssService;
import com.stone.boot.file.domain.bo.OssCallbackResult;
import com.stone.boot.file.domain.bo.OssPolicyResult;
import com.stone.starter.core.util.result.Results;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 测试
 *
 * @author Mr_wenpan@163.com 2021/8/19 2:38 下午
 */
@RestController
@Api(tags = "OssController", value = "Oss管理")
@RequestMapping("/aliyun/oss")
public class OssController {
    @Autowired
    private OssService ossServiceImpl;

    @ApiOperation("oss上传签名生成")
    @GetMapping("/policy")
    public ResponseEntity<OssPolicyResult> policy() {
        OssPolicyResult ossPolicyResult = ossServiceImpl.policy();
        return Results.success(ossPolicyResult);
    }

    @ApiOperation("oss上传成功回调")
    @PostMapping("callback")
    public ResponseEntity<OssCallbackResult> callback(HttpServletRequest request) {
        OssCallbackResult ossCallbackResult = ossServiceImpl.callback(request);
        return Results.success(ossCallbackResult);
    }

    @ApiOperation("oss文件上传")
    @PostMapping(value = "upload")
    public Map<String, Object> uploadOssFile(MultipartFile file, String fileName) {
        return ossServiceImpl.upload(file, fileName);
    }
}
